package customerService

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/customerservicegroup"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpsertCustomerServiceGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增或修改客服群管理
func NewUpsertCustomerServiceGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpsertCustomerServiceGroupLogic {
	return &UpsertCustomerServiceGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpsertCustomerServiceGroupLogic) UpsertCustomerServiceGroup(req *types.UpsertCustomerServiceGroupReq) (resp *types.Empty, err error) {
	u, err := l.svcCtx.SettingService.CustomerService.UpsertCustomerServiceGroup(l.ctx, &customerservicegroup.UpsertCustomerServiceGroupReq{
		MerchantId:        1,                                                              // 商户ID
		GroupPic:          req.GroupPic,                                                   // 群图标
		Title:             req.Title,                                                      // 主标题
		Subheading:        req.Subheading,                                                 // 副标题
		CommunicationType: rpc.CommunicationType(req.CommunicationType.CommunicationType), // 通讯类型
		JumpAddress:       req.JumpAddress,                                                // 跳转地址
		Status:            rpc.StatusType(req.Status),                                     // 状态,0:禁用,1:启用
	})

	if err != nil {
		logc.Error(l.ctx, "UpsertCustomerServiceGroup err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
